package com.ghsc.ghxc.jsb.ui.home.activity

import androidx.lifecycle.MutableLiveData
import com.cn.appcore.base.BaseViewModel
import com.cn.appcore.ext.executeListResponse
import com.cn.appcore.ext.executeResponse
import com.cn.appcore.http.bean.BaseResponse
import com.ghsc.ghxc.jsb.api.ApiMarket
import com.ghsc.ghxc.jsb.ui.home.bean.PrepareBuyBean
import com.ghsc.ghxc.jsb.ui.home.bean.PrepareResult
import com.ghsc.ghxc.jsb.ui.my.bean.AddressDetailBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.home.activity
 * 类名：SubmitOrderViewModel
 * 创建时间：2024/5/6 15:59
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
class SubmitOrderViewModel  : BaseViewModel() {


    /**
     * 收货地址
     */
    val onAddressListData: MutableLiveData<List<AddressDetailBean>> = MutableLiveData()
    fun onAddressListMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onAddressListData(paras) }
            executeListResponse(
                response,
                { onAddressListData.value = response.data},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }
    /**
     *  预下单
     */
    var prepareBuyResult = MutableLiveData<BaseResponse<PrepareResult>>()
    fun prepareBuy(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onPrepareBuy(paras) }
            executeResponse(
                response,
                { prepareBuyResult.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }


}